xenapi: Extension to get vif total i/o stats.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 20 Nov 2007 15:18:09 +0000 (15:18 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 20 Nov 2007 15:18:09 +0000 (15:18 +0000)
From: Stefan de Konink <skinkie@xs4all.nl>
Signed-off-by: Keir Fraser <keir.fraser@eu.citrix.com>
tools/python/xen/xend/XendAPI.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/XendMonitor.py
tools/python/xen/xend/XendNode.py

index c64b38ec21c5c34be49fcd7a95f455272d87f49b..1a0fb4839bd5dfcf26f2e1618dda7c4e7cdc50a2 100644 (file)
@@ -2111,6 +2111,8 @@ class XendAPI(object):
 
     VIF_metrics_attr_ro = ['io_read_kbs',
                            'io_write_kbs',
+                           'io_total_read_kbs',
+                           'io_total_write_kbs',
                            'last_updated']
     VIF_metrics_attr_rw = []
     VIF_metrics_methods = []
@@ -2125,6 +2127,8 @@ class XendAPI(object):
         return xen_api_success(
             { 'io_read_kbs'  : vm.get_dev_property('vif', ref, 'io_read_kbs'),
               'io_write_kbs' : vm.get_dev_property('vif', ref, 'io_write_kbs'),
+              'io_total_read_kbs'  : vm.get_dev_property('vif', ref, 'io_total_read_kbs'),
+              'io_total_write_kbs' : vm.get_dev_property('vif', ref, 'io_total_write_kbs'),
               'last_updated' : now()
             })
 
@@ -2134,6 +2138,12 @@ class XendAPI(object):
     def VIF_metrics_get_io_write_kbs(self, session, ref):
         return self._VIF_get(ref, 'io_write_kbs')
 
+    def VIF_metrics_get_io_total_read_kbs(self, _, ref):
+        return self._VIF_get(ref, 'io_total_read_kbs')
+
+    def VIF_metrics_get_io_total_write_kbs(self, session, ref):
+        return self._VIF_get(ref, 'io_total_write_kbs')
+
     def VIF_metrics_get_last_updated(self, _1, _2):
         return xen_api_success(now())
 
index 79e2f859777a08e7950aa720ea931d08a7cde6f0..eaee766cf0dc53383f64f2b586c4201c2c5327c7 100644 (file)
@@ -2606,9 +2606,14 @@ class XendDomainInfo:
                 rx_bps, tx_bps = xennode.get_vif_util(self.domid, devid)
                 config['io_read_kbs'] = rx_bps/1024
                 config['io_write_kbs'] = tx_bps/1024
+                rx, tx = xennode.get_vif_stat(self.domid, devid)
+                config['io_total_read_kbs'] = rx/1024
+                config['io_total_write_kbs'] = tx/1024
             else:
                 config['io_read_kbs'] = 0.0
-                config['io_write_kbs'] = 0.0                
+                config['io_write_kbs'] = 0.0          
+                config['io_total_read_kbs'] = 0.0
+                config['io_total_write_kbs'] = 0.0
 
             config['security_label'] = config.get('security_label', '')
 
index a8d894c4ec01123c73728ebff7fb228c77e88dc0..83fcb182d361626354c8723126ca5a04dbfb7121 100644 (file)
@@ -63,6 +63,8 @@ class XendMonitor(threading.Thread):
     @type domain_vcpus_util: {domid: {vcpuid: float, vcpuid: float}}
     @ivar domain_vifs_util: Bytes per second for VIFs indexed by domain
     @type domain_vifs_util: {domid: {vifid: (rx_bps, tx_bps)}}
+    @ivar domain_vifs_stat: Total amount of bytes used for VIFs indexed by domain
+    @type domain_vifs_stat: {domid: {vbdid: (rx, tx)}}
     @ivar domain_vbds_util: Blocks per second for VBDs index by domain.
     @type domain_vbds_util: {domid: {vbdid: (rd_reqps, wr_reqps)}}    
     
@@ -83,6 +85,7 @@ class XendMonitor(threading.Thread):
         # instantaneous statistics
         self._domain_vcpus_util = {}
         self._domain_vifs_util = {}
+        self._domain_vifs_stat = {}
         self._domain_vbds_util = {}
         self.pifs_util = {}
 
@@ -107,6 +110,13 @@ class XendMonitor(threading.Thread):
         finally:
             self.lock.release()
 
+    def get_domain_vifs_stat(self):
+        self.lock.acquire()
+        try:
+            return self._domain_vifs_stat
+        finally:
+            self.lock.release()
+
     def get_pifs_util(self):
         self.lock.acquire()
         try:
@@ -269,6 +279,7 @@ class XendMonitor(threading.Thread):
                     if domid not in self._domain_vifs:
                         self._domain_vifs[domid] = vifs
                         self._domain_vifs_util[domid] = {}
+                        self._domain_vifs_stat[domid] = {}
                         continue
                 
                     for devid, (usage_at, rx, tx) in vifs.items():
@@ -286,6 +297,8 @@ class XendMonitor(threading.Thread):
                         # not the guest interface
                         self._domain_vifs_util[domid][devid] = \
                              (tx_util, rx_util)
+                        self._domain_vifs_stat[domid][devid] = \
+                             (float(tx), float(rx))
                         
                     self._domain_vifs[domid] = vifs
 
@@ -313,6 +326,7 @@ class XendMonitor(threading.Thread):
                     if domid not in active_domids:
                         del self._domain_vifs_util[domid]
                         del self._domain_vifs[domid]
+                        del self._domain_vifs_stat[domid]
                 for domid in self._domain_vbds_util.keys():
                     if domid not in active_domids:
                         del self._domain_vbds_util[domid]
index cde65142f1774a145f0da5391958bf5cc9984c13..841403f71de0ea716dbd3ca1dc96b6382a233292 100644 (file)
@@ -651,6 +651,12 @@ class XendNode:
             return vif_loads[domid].get(vifid, (0.0, 0.0))
         return (0.0, 0.0)
 
+    def get_vif_stat(self, domid, vifid):
+        vif_loads = self.monitor.get_domain_vifs_stat()
+        if domid in vif_loads:
+            return vif_loads[domid].get(vifid, (0.0, 0.0))
+        return (0.0, 0.0)
+
     def get_vbd_util(self, domid, vbdid):
         vbd_loads = self.monitor.get_domain_vbds_util()
         if domid in vbd_loads: